<?php
/*
 *      index.php
 *      
 *      Copyright 2011 Vitaliy Rakitin <virak@ukr.net>
 *      
 *      This program is free software; you can redistribute it and/or modify
 *      it under the terms of the GNU General Public License as published by
 *      the Free Software Foundation; either version 2 of the License, or
 *      (at your option) any later version.
 *      
 *      This program is distributed in the hope that it will be useful,
 *      but WITHOUT ANY WARRANTY; without even the implied warranty of
 *      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *      GNU General Public License for more details.
 *      
 *      You should have received a copy of the GNU General Public License
 *      along with this program; if not, write to the Free Software
 *      Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
 *      MA 02110-1301, USA.
 */

?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
	"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
	<title>Поле</title>
	<meta http-equiv="content-type" content="text/html;charset=utf-8" />
	<meta name="generator" content="Geany 0.20" />
</head>
<body>
<?php

function displayform(&$field) {
	echo "<form name='edit' action='./index.php?dictionary=".$_GET["dictionary"]."&tabular=".$_GET["tabular"]."&field=".$field->uuid."' method='post'>";
	echo "<table>";
	echo "<tr><td>uuid</td><td><input type='text'  disabled='disabled' name='uuid' size='32' value='".$field->uuid."'></td></tr>";
	echo "<tr><td>name</td><td><input type='text' name='name' size='32' value='".$field->name."'></td></tr>";
	echo "<tr><td>length</td><td><input type='text' name='length' size='32' value='".$field->length."'></td></tr>";
	echo "<tr><td>type</td><td><input type='text' name='type' size='32' value='".$field->type."'></td></tr>";
	//echo "<tr><td>isprimary</td><td><input type='checkbox' name='isprimary' ";//.$field->isprimary ? "checked":""."></td></tr>";
	//if ($field->isprimary) {echo "checked";} else {echo "";}
	//echo $field->isprimary ? "checked":"";
	//echo "></td></tr>";
	echo "<tr><td>luobject</td><td><input type='text' name='luobject' size='32' value='".$field->luobject."'></td></tr>";
	echo "<tr><td>ludisplay</td><td><input type='text' name='ludisplay' size='32' value='".$field->ludisplay."'></td></tr>";
	echo "<tr><td>beforechange</td><td><textarea rows='5' cols='128' name='beforechange'>".$field->beforechange."</textarea></td></tr>";
	echo "<tr><td>afterchange</td><td><textarea rows='5' cols='128' name='afterchange'>".$field->afterchange."</textarea></td></tr>";
	echo "</table>";
	echo "<input type='submit' name='save' value='Сохранить'>";
	echo "</form>";
}

function save(&$field) {
	$field->name = $_POST["name"];
	$field->type = $_POST["type"];
	$field->length = $_POST["length"];
	$field->luobject = $_POST["luobject"];
	$field->ludisplay = $_POST["ludisplay"];
	$field->beforechange = $_POST["beforechange"];
	$field->afterchange = $_POST["afterchange"];
	//$field->onchange = $_POST["onchange"];
	//$field->isprimary = array_key_exists("isprimary",$_POST);
}


	require_once($_SERVER['DOCUMENT_ROOT']."/classes/metadata/osmetadata.php");
	//echo "GET: <pre>".print_r($_GET,1)."</pre><br>";
	//echo "POST: <pre>".print_r($_POST,1)."</pre><br>";
	
	echo "<a href='../.././fields/index.php?dictionary=".$_GET["dictionary"]."&tabular=".$_GET["tabular"]."'><< Поля</a><br>";
	
	$dictionary = $metadata->dictionaries->byuuid($_GET["dictionary"]);
	if ($dictionary) {
		$tabular = $dictionary->tabulars->byuuid($_GET["tabular"]);
		if ($tabular) {
			$field = $tabular->fields->byuuid($_GET["field"]);
			if ($field) {
				if (array_key_exists("save",$_POST)) {
					save($field);
				} 
			} else {
				$field = $tabular->fields->add();
			}
			displayform($field);
		} else {
			echo "Таблица с uuid ".$_GET["tabular"]." не найдена!";
		}
	} else {
		echo "Словарь с uuid ".$_GET["dictionary"]." не найден!";
	}
	
	//echo "session: <pre>".print_r($_SESSION,1)."</pre><br>";
?>
</body>
</html>
